package com.jiajia.study;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageBuilder;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title: HeadersApplication
 * @Author zjj
 * @Package com.jiajia.study
 * @Date 2024/3/9 14:29
 * @description:
 */

@SpringBootApplication
public class HeadersApplication implements ApplicationRunner {

    @Resource
    private RabbitTemplate rabbitTemplate;

    public static void main(String[] args) {
        SpringApplication.run(HeadersApplication.class,args);
    }

    @Override
    public void run(ApplicationArguments args) throws Exception {
        Thread.sleep(3000);
        MessageProperties messageProperties = new MessageProperties();
        Map<String,Object> headers = new HashMap<>();
        headers.put("type","m");
        headers.put("status",0);
        messageProperties.setHeaders(headers);
        Message message = MessageBuilder.withBody("hello headers".getBytes(StandardCharsets.UTF_8)).andProperties(messageProperties).build();
        rabbitTemplate.convertAndSend("queue.headers.a",message);

    }
}
